﻿using System;
using System.Collections.Generic;
using HMIS.FrameWork.DomainBase;
using HMIS.Infrastructure.Core.Authority;
using HMIS.Infrastructure.Core.Repositories;

namespace HMIS.Infrastructure.Facade.Authority.Impl
{
    public class UserRoleDepFacadeImpl : IUserRoleDepFacade
    {
        private readonly IUserRoleDepRepository UserRoleDepRepository;
		public UserRoleDepFacadeImpl(IUserRoleDepRepository UserRoleDepRepository)
        {
			this.UserRoleDepRepository = UserRoleDepRepository;
        }

        #region IHospUserFacade 成员

        public void PhysicsDelete(string id)
        {
			UserRoleDepRepository.PhysicsDelete(id);
        }

		public IList<object[]> QueryUserListByCode(
			string query,
			string userCode,
			string roleCode,
			string deptCode,
			int start,
			int limit,
			string sort,
			string dir,
			List<DataFilter> filters,
			out long total)
		{
			return UserRoleDepRepository.QueryUserListByCode(
				query, 
				userCode,
				roleCode, 
				deptCode, 
				start, 
				limit, 
				sort, 
				dir, 
				filters, 
				out total);
		}

		public void Save(UserRoleDep entity)
		{
			IList<UserRoleDep> userRoleDepList = UserRoleDepRepository.GetExists(entity.Person.Id, entity.Role.Id, entity.Department.Id);
			if (userRoleDepList.Count > 0)
				throw new Exception("已存在相同的用户权限:");

			UserRoleDepRepository.SaveOrUpdate(entity);
		}

        #endregion
    }
}
